

//include ("PlayScene.js");

var res = {
    bg: "img/bg.png",
    bt1: "img/bt1.png",
    bt2: "img/bt2.png",
    sushi: "img/ball.png",
    sushi_black: "img/ball_black.png",
    car: "img/hand.png",
    logo: "img/logo.png",
    gift: "img/gift.png",
    ball: "img/ball.png",
};

var icons_file =    ["img/icon_11320277_19616756_1417483574.png",
                     "img/icon_11662928_20755191_1427174976.png",
                     "img/icon_97949_19550267_1416292977.png",
                     "img/icon_11260412_20454755_1423131797.png",
                     "img/icon_10170898_20378361_1422544366.jpeg",
                     "img/icon_10563109_20846233_1428369719.png",
                     "img/icon_10125368_20805666_1427892272.png"];


var StartLayer = cc.Layer.extend({
        ctor:function() {
                this._super();
                var size = cc.winSize;
                
                /*********************************************************/
                //添加文字
                var helloLabel = new cc.LabelTTF("图标消消乐DEMO", "", 35);
                helloLabel.x = size.width / 2;
                helloLabel.y = size.height - 120;
                helloLabel.setColor(cc.color(255,255,0));
                this.addChild(helloLabel, 2);

                var title_bg = new cc.Sprite(res.bt1);
                title_bg.x = size.width / 2;
                title_bg.y = size.height - 120;
                //this.addChild(title_bg, 1);

                /*********************************************************/
                //添加背景图片
                this.bgSprite = new cc.Sprite(res.bg);
                this.bgSprite.attr({
                        x:size.width / 2,
                        y:size.height / 2,
                });
                this.addChild(this.bgSprite, 0); 


                /*********************************************************/
                //添加按钮
                /*
                var startItem = new cc.MenuItemImage(
                        res.bt1,
                        res.bt2,
                        function() {
                                cc.director.pushScene(new PlayScene());
                        }, this);

                startItem.attr({
                        x: size.width / 2,
                        y: size.height / 2 - 20,
                        anchorX: 0.5,
                        anchorY: 0.5,
                });
                */


                console.log(size.width);
                console.log(size.height);


                var SimpleMenuItem = new cc.MenuItemFont(
                                "简单(4X5)",
                                function () {
                                        var s = new PlayScene();
                                        s.x_count = 4;
                                        s.y_count = 5;
                                        s.replace_time = 0.1;
                                        //s.initIcons();
                                        //cc.director.runScene(s);
                                        cc.director.pushScene(s);
                                }, this);
                SimpleMenuItem.attr({
                        x: size.width/2,
                        y: size.height / 2 + 50,
                        anchorX: 0.5,
                        anchorY: 0.5
                });

                var MediumMenuItem = new cc.MenuItemFont(
                                "中等(5X6)",
                                function () {
                                        var s = new PlayScene();
                                        s.x_count = 5;
                                        s.y_count = 6;
                                        s.replace_time = 0.09;
                                        //s.initIcons();
                                        //cc.director.runScene(s);
                                        cc.director.pushScene(s);
                                }, this);
                MediumMenuItem.attr({
                        x: size.width/2,
                        y: size.height / 2 ,
                        anchorX: 0.5,
                        anchorY: 0.5
                });

                var HardMenuItem = new cc.MenuItemFont(
                                "困难(6X7)",
                                function () {
                                        var s = new PlayScene();
                                        s.x_count = 6;
                                        s.y_count = 7;
                                        s.replace_time = 0.08;
                                        //s.initIcons();
                                        //cc.director.runScene(s);
                                        cc.director.pushScene(s);
                                }, this);
                HardMenuItem.attr({
                        x: size.width/2,
                        y: size.height / 2 - 50,
                        anchorX: 0.5,
                        anchorY: 0.5,
                });



                var menu = new cc.Menu([SimpleMenuItem, MediumMenuItem, HardMenuItem]);
                menu.x = 0; 
                menu.y = 0; 
                menu.setColor(cc.color(255,0,0));
                this.addChild(menu, 1);


                var logo = new cc.Sprite(res.logo);
                logo.attr({
                        x: size.width - 50,
                        y: 25,
                });
                logo.setScale(0.7);
                this.addChild(logo, 10);

                var logo_txt = new cc.LabelTTF("更多精彩就在应用宝", "", 10);
                logo_txt.attr({
                        x: size.width - 70,
                        y: 15,
                        anchorX: 1,
                        color: cc.color(0,23,233),
                });
                //this.addChild(logo_txt, 10);
                //

                /*
                var ball_sprite = new cc.Sprite(res.ball);
                ball_sprite.attr({
                        x: size.width / 2,
                        y: 0, 
                });
                ball_sprite.setScale(2);
                this.addChild(ball_sprite, 0);
                */

                return true;

        }
});


var StartScene = cc.Scene.extend({
        onEnter:function() {
                this._super();
                var layer = new StartLayer();
                this.addChild(layer);
        }
});



var g_resources = [];


function onLoad ()
{
        cc.game.onStart = function()
        {
                //load resources
                cc.LoaderScene.preload(g_resources, function () {
                        cc.director.runScene(new StartScene());
                }, this);

                cc.view.setDesignResolutionSize(320, 480, cc.ResolutionPolicy.SHOW_ALL);
                cc.view.resizeWithBrowserSize(true);
        };
        cc.game.run("gameCanvas");
}

